﻿@model ABCTile.ViewModel.UserIndexData
<div id = "UserList">
    <table>
        <tr>
            <th>
                UserFname
            </th>
            <th>
                UserMname
            </th>
            <th>
                UserLname
            </th>
            <th>
                UserEmail
            </th>
            <th>
                FullName
            </th>
            <th>
                Role
            </th>
            <th></th>
        </tr>
    @if (Model.PagedUsers != null && Model.PagedUsers.Count > 0)
    {
        foreach (var item in Model.PagedUsers) {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.UserFname)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.UserMname)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.UserLname)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.UserEmail)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.FullName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Role.RoleName)
                </td>
                @if (item.UserID == User.Identity.Name)
                {
                <td>
                    @Html.ActionLink("Edit", "Edit", new { id = item.UserID }) |
                    @Html.ActionLink("Details", "Details", new { id = item.UserID }) |
                    @Html.ActionLink("Delete", "Delete", new { id = item.UserID })
                </td>
                }
                else
                {
                    <td></td>
                }
            </tr>
        }
    }

    </table>
    <div>
        Page @(Model.PagedUsers.PageCount < Model.PagedUsers.PageNumber ? 0 : Model.PagedUsers.PageNumber)
        of @Model.PagedUsers.PageCount
        &nbsp;
        @if (Model.PagedUsers.HasPreviousPage)
        {
            @Ajax.ActionLink("<<", "UserIndexForSearchingAndPagingWithAjax", new { page = 1 },
                new AjaxOptions
                {
                    UpdateTargetId = "UserList",
                    InsertionMode = InsertionMode.Replace,
                    HttpMethod = "GET"
                }) 
            @Html.Raw("&nbsp;");
            @Ajax.ActionLink("< Prev", "UserIndexForSearchingAndPagingWithAjax", new { page = Model.PagedUsers.PageNumber - 1 },
                new AjaxOptions
                {
                    UpdateTargetId = "UserList",
                    InsertionMode = InsertionMode.Replace,
                    HttpMethod = "GET"
                })
        }
        else
        {
            @: <<
            @Html.Raw("&nbsp;");
            @: < Prev
        }
        &nbsp;
        @if (Model.PagedUsers.HasNextPage)
        {
            @Ajax.ActionLink("Next > ", "UserIndexForSearchingAndPagingWithAjax", new { page = Model.PagedUsers.PageNumber + 1 },
                new AjaxOptions
                {
                    UpdateTargetId = "UserList",
                    InsertionMode = InsertionMode.Replace,
                    HttpMethod = "GET"
                })
            @Html.Raw("&nbsp;");
            @Ajax.ActionLink(">>", "UserIndexForSearchingAndPagingWithAjax", new { page = Model.PagedUsers.PageCount },
                new AjaxOptions
                {
                    UpdateTargetId = "UserList",
                    InsertionMode = InsertionMode.Replace,
                    HttpMethod = "GET"
                })
        }
        else
        {
            @:Next >
            @Html.Raw("&nbsp;") 
            @:>>
        }
    </div>
</div>